package fi.laurea.datalogger;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.google.gson.Gson;

import fi.laurea.jsonbus.Receiver;
import fi.laurea.jsonbus.ReceiverListener;

public class TempTest extends JPanel implements  ReceiverListener {

	Receiver receiver;
	Gson gson ;
	JTextField field1;
	JTextField field2;
	JTextField field3;
	JTextField field4;
	JLabel label1;
	JLabel label2;
	JLabel label3;
	JLabel label4;
	
	public TempTest(){
		this.gson = new Gson();
		this.receiver = new Receiver ("logger","matti",this);
		this.field1 = new JTextField("updating...");
		this.field2 = new JTextField("updating...");
		this.field3 = new JTextField("updating...");
		this.field4 = new JTextField("updating...");
		this.label1 = new JLabel("Value 1");
		this.label2 = new JLabel("Value 2");
		this.label3 = new JLabel("Value 3");
		this.label4 = new JLabel("Value 4");
		this.field1.setEditable(false);
		this.field2.setEditable(false);
		this.field3.setEditable(false);
		this.field4.setEditable(false);
		this.setLayout(new GridLayout(4,2));
		this.add(label1);
		this.add(field1);
		this.add(label2);
		this.add(field2);
		this.add(label3);
		this.add(field3);
		this.add(label4);
		this.add(field4);
		
		
		
		
	}
	
	
	
	@Override
	public void prosessGloballMessage(String json) {
		DataMessage message = (DataMessage) gson.fromJson(json, DataMessage.class);
		this.field1.setText(message.getValues()[0]);
		this.field2.setText(message.getValues()[1]);
		this.field3.setText(message.getValues()[2]);
		this.field4.setText(message.getValues()[3]);
	}

	@Override
	public void prosessPrivateMessage(String json) {
		// TODO Auto-generated method stub
		
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		TempTest test = new TempTest();
		frame.add(test);
		frame.setVisible(true);
	}
	
}
